﻿package microframe.ui
{
	import com.ux.manager.StageManager;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	
	/**
	 * @author winnie
	 */	
	public class Loading extends MovieClip
	{
		private static var _instance : Loading;
		public var txt : TextField;
		
		private static function get instance():Loading
		{
			if( _instance == null ) _instance = new Loading();
			return _instance;
		}
		
		
		/**
		 * 로딩바 플레이
		 */		
		public static function ON():void
		{
			onStageResize( null );
			
			StageManager.stage.addChild( instance );
			StageManager.stage.addEventListener(Event.RESIZE, onStageResize );
		}
		
		
		
		/**
		 * @param per 퍼센테이지에 맞게 로딩 텍스트 노출
		 */		
		public static function LOADING( per:Number ):void
		{
			trace(" ==> Loading LOADING : " + per );
			instance.txt.text = String( int( per ) );
		}
		
		/**
		 * 로딩바 끄기 
		 */		
		public static function OFF():void
		{
			StageManager.stage.removeEventListener(Event.RESIZE, onStageResize );
			if( StageManager.stage.contains( instance ) ) StageManager.stage.removeChild( instance );
		}
		
		
		
		/**
		 * @param e 로딩바 위치 조정
		 */		
		public static function onStageResize( e:Event ):void
		{
			instance.x = ( StageManager.stage.stageWidth - instance.width )/2;
			instance.y = ( StageManager.stage.stageHeight - instance.height )/2;
		}
		
		
		/**
		 * Loading
		 */		
		public function Loading()
		{
			super();
			StageManager.stage.addChild( this );
			
			
			//-----------------------------------------------------------------------------------
			//
			// 임시
			//
			//-----------------------------------------------------------------------------------
			//this.visible = false;
			
		}
		
		override public function get width():Number
		{
			return 0;
		}
		
		override public function get height():Number
		{
			return 0;
		}
		
	}
	
}